package com.zl.tesseract.scanner.greendao.services;

import com.zl.tesseract.scanner.beans.CollectBean;
import com.zl.tesseract.scanner.greendao.GreenDaoHelper;
import com.zl.tesseract.scanner.greendao.db.CollectBeanDao;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

public class CollectBeanService {

    private static CollectBeanDao collectBeanDao;


    public static void saveOne(CollectBean collectBean) {
        if(collectBeanDao == null){
            collectBeanDao = GreenDaoHelper.getDaoSession().getCollectBeanDao();
        }
        collectBeanDao.save(collectBean);
    }

    public static void saveList(List<CollectBean> list) {
        for (CollectBean collectBean : list) {
            saveOne(collectBean);
        }
    }

    public static List<CollectBean> findAll() {
        if(collectBeanDao == null){
            collectBeanDao = GreenDaoHelper.getDaoSession().getCollectBeanDao();
        }
        return collectBeanDao.loadAll();
    }

    public static CollectBean findOneByOrderId(String order_id) {
        if(collectBeanDao == null){
            collectBeanDao = GreenDaoHelper.getDaoSession().getCollectBeanDao();
        }
        QueryBuilder<CollectBean> queryBuilder = collectBeanDao.queryBuilder();
        return queryBuilder.where(CollectBeanDao.Properties.Order_id.eq(order_id)).unique();
    }

    public static void deleteOne(CollectBean collectBean) {
        if(collectBeanDao == null){
            collectBeanDao = GreenDaoHelper.getDaoSession().getCollectBeanDao();
        }
        collectBeanDao.delete(collectBean);
    }

    public static void deleteAll() {
        if(collectBeanDao == null){
            collectBeanDao = GreenDaoHelper.getDaoSession().getCollectBeanDao();
        }
        collectBeanDao.deleteAll();
    }
}